import java.util.Random;
import java.util.Scanner;


/**
 * @author 10277
 */
public class NewGuessNumber {

    public static void main(String[] args) {
        guess();
    }
    public static void guess() {
        Random random = new Random();
        int[] a = new int[4];
        int[] b = new int[4];
        int c = random.nextInt(10);
        a[0] = c;
        for (int i = 0; i < a.length; i++) {
            c = random.nextInt(10);
            for (int num = 0; num < i; num++) {
                while (c == a[num]) {
                    c = random.nextInt(10);
                    num = 0;
                }
            }
            a[i] = c;
        }
        for (int i = 0; i < a.length; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (a[i] == a[j]) {
                    a[j] = (a[j] * a[j] + 1) % 10;
                }
            }
        }
        input(a,b);
    }
    public static void input(int[] a, int[] b){
        Scanner scanner = new Scanner(System.in);
        int times = 4;
        //可以猜多少次
        while (times > 0) {
            int t = 1;
            System.out.println("请输入四个不重复的数字");
            while (t > 0) {
                for (int i = 0; i < a.length; i++) {
                    System.out.print("输入第" + (i + 1) + "个数");
                    b[i] = scanner.nextInt();
                }
                for (int i = 0; i < a.length; i++) {
                    for (int j = 0; j < a.length; j++) {
                        if ((b[i] == b[j]) && (j != i)) {
                            t = 1;
                            break;
                        } else {
                            t = 0;
                        }
                    }
                    if (t == 1) {
                        break;
                    }
                }
                if (t == 1) {
                    System.out.println("输入了重复的数字，请重新输入");
                }
            }
            int x = 0, y = 0;
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a.length; j++) {
                    if (a[i] == b[i]) {
                        x++;
                        break;
                    }
                    if (b[j] == a[i]) {
                        y++;
                    }
                }
            }
            if (x == 4) {
                System.out.println("你猜对了！你好棒！");
                break;
            } else {
                times--;
                System.out.printf("%dA%dB \n", x, y);
                if (times != 0) {
                    System.out.printf("你还有%d次机会！\n", times);
                }
                if (times== 0) {
                    System.out.println("sorry,次数用完了！");
                    System.out.println("数字为：");
                    for (int i = 0; i < a.length; i++) {
                        System.out.print(a[i]);
                    }
                    break;
                }
                System.out.println("请输入:1(继续)/2（退出并查看数字）");
                int h;
                h = scanner.nextInt();
                if (h == 1) {
                    continue;
                }
                if (h == 2) {
                    System.out.println("原数为：");
                    int i = 0;
                    while (i < a.length) {
                        System.out.print(a[i]);
                        i++;
                    }
                    break;
                }
            }
        }
    }
}